package com.itcast.architecture.controller;

import com.itcast.architecture.common.Result;
import com.itcast.architecture.style_1.Style1;
import com.itcast.architecture.style_2.Style2;
import com.itcast.architecture.style_3.Style3;
import com.itcast.architecture.style_4.Style4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/style")
public class SwpuController {
    @Autowired
    private Style1 style1;
    @Autowired
    private Style2 style2;
    @Autowired
    private Style3 style3;
    @Autowired
    private Style4 style4;
    @GetMapping("/{id}")
    public List<Result> output_1(@PathVariable Integer id){
        List<Result> resultList=new ArrayList<>();
        List<String> str=new ArrayList<>();

        if (id==1){
            str=style1.main();
            System.out.println("主程序-子程序软件体系结构");
        }
        else if (id==2){
            str=style2.main();
            System.out.println("面向对象软件体系结构");
        }
        else if (id==3){
            str=style3.main();
            System.out.println("事件系统软件体系结构");
        }
        else if (id==4){
            try {
                str=style4.main();
                System.out.println("管道-过滤软件体系结构");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        for (int i = 0; i < str.size(); i++) {
            if (i==0){
                resultList.add(new Result(str.get(i),"D:\\"+id+".png"));
                continue;
            }
            resultList.add(new Result(str.get(i)));
        }
        return resultList;

    }
}


